﻿@{
    ViewBag.Title = "Users";
}

@section scripts
{  
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                            <span class="separator"></span>
                        <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true">新增</a>                            
                        <a class="mini-button" id="save" name="save" iconCls="icon-edit" onclick="modify" plain="true">修改</a>
                        <a class="mini-button" id="saveAiPs" name="saveAiPs" iconCls="icon-save" onclick="saveAiPs" plain="true">保存激活码</a>
                        <a class="mini-button" id="init" name="init" iconCls="icon-ok" onclick="initpwd" plain="true">缺省密码</a>
                        <a class="mini-button" id="edit" name="edit" iconCls="icon-edit" onclick="editpwd" plain="true">修改密码</a>
                            <span class="separator"></span>
                        <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="removeInfo" plain="true">删除</a>                        
                        @*<a class="mini-button" id="ClearPos" name="Agent" iconCls="icon-tip" onclick="setClearPOS" plain="true">注销前台</a>*@
                        <span class="separator"></span>
                        <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                    </td>
                </tr>
            </table>       
        </div>        
        <table>
            <tr>
                <td width ="70px" align="right">用户类型：</td>
                <td width ="150px">
                    <input id="comType" name ="FType" class="mini-combobox" style="width:150px;" 
                    showNullItem="false" value="0" allowInput="false" align="left" data ="comType"/>  
                </td>  
                <td width ="90px" align="right">编码或名称: </td>
                <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey" name = "FSearchKey" onkeypress="setkeyPress()"/></td>             
                <td width ="100px" align="center">
                    <a class="mini-button" iconCls="icon-search" onclick="search" plain="true">查询</a>
                </td>
            </tr>
        </table>
        <div class="mini-fit">
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="GetList"
                    allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client" onload="loaded">
                <div property="columns">
                    <div type="checkcolumn" >选行</div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FNumber" name="FNumber" width="120" headeralign="center" allowsort="true">用户编码</div>
                    <div field="FName" name="FName" width="120" headeralign="center" allowsort="true">用户名称</div>
                    <div field="FUses_name" name="FUses_name" width="120" headeralign="center" allowsort="true">自定义码</div>
                    <div field="userType" name="userType" width="120" headeralign="center" allowsort="true">用户类型</div>
                    <div field="FCorpName" name="FCorpName" width="120" headeralign="center" allowsort="true">商户名称</div>
                    <div field="FTelephone" name="FTelephone" width="100" headeralign="center" allowsort="true">电话</div>
                    <div field="FAiPassphrase" name="FAiPassphrase" width="300" headerAlign="center">AI激活码
                            <input property="editor" class="mini-textbox" style="width:100%;"/>
                    </div> 
                    <div field="FAddress" name="FPhone" width="150" headeralign="center" allowsort="true">地址</div>
                    <div field="FCreatDate" name="FCreatDate" width="80" headeralign="center" allowsort="true">注册日期</div>
                    <div field="FRemark" name="FRemark" width="150" headeralign="center" allowsort="true">备注</div>
                </div>
            </div>
        </div>
<script>
    var comType = [{ "id": "0", "text": "普通用户" },
                    { "id": "4", "text": "关联批发客户用户" },
                    { "id": "1", "text": "所有用户" }];

    mini.parse();
    var grid = mini.get("datagrid1");
    function FormShown() {
        
        LoadListData();
    }
    function setkeyPress() {
        LoadListData();
    }
   
    function loaded(e) {
        if (e.data.length == 0) {
            mini.getbyName("saveAiPs").set({ visible: false });
            grid.updateColumn("FAiPassphrase", { visible: false });
            return;
        }
        if (e.data[0].FSetAlFlag == 1) {
            mini.getbyName("saveAiPs").set({ visible: true });
            grid.updateColumn("FAiPassphrase", { visible: true });
        }
        else {
            mini.getbyName("saveAiPs").set({ visible: false });
            grid.updateColumn("FAiPassphrase", { visible: false });
        }
    }

    function saveAiPs() {        
        var rows = grid.getChanges();
        var maijson = mini.encode(rows);
        $.post("saveUserAiInfo", { json: maijson }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                grid.reload();
                mini.alert("保存成功");
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.getbyName("SaveInfo").enable();
        });
    }

    //加载资料列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var mType = mini.getbyName("FType").getValue();
        var json = "[{";
        json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + '"mType":' + '"' + mType + '",';
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
        json = json + "}]";
        grid.load({ mjson: json });
    }

    //搜索资料列表
    function search() {
        LoadListData();
    }

    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        mini.open({
            url: "/User/UserInfo?mSystemAppID="+parent.window.getSystemAppID(),
            title: "用户资料", width: 650, height: 320,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0" };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }

    //修改资料
    function modify() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/User/UserInfo?mSystemAppID=" + parent.window.getSystemAppID(),
                title: "用户资料", width: 650, height: 320,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function initpwd() {
        mini.confirm("确定要将密码设置为缺省？", "提示",
            function (action) {
                if (action == "ok") {
                    var row = grid.getSelected();
                    if (row) {
                        $.post("InitalPwd", { json: '{ FItemID:' + row.FItemID + ', mSystemAppID: \'' + parent.window.getSystemAppID() + '\' }' }, function (data) {
                            var mdata = mini.decode(data);
                            if (mdata.status == "1")
                                mini.alert("设置成功!缺省密码:000000(六个0)");
                            else
                                mini.showTips({ content: mdata.error, state: "danger", x: "center", y: "top", timeout: 4000 });
                        });
                    } else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

    function editpwd() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/User/EditPwd",
                title: "密码修改", width: 430, height: 320,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //删除资料
    function removeInfo() {
        var row = grid.getSelected();
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        var json = "{'FItemID':'" + row.FItemID + "'}";
                        $.post("RemoveUserInfo", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: "删除成功！", state: "success", x: "center", y: "top", timeout: 4000 });
                                grid.reload();
                            }
                            else {
                                mini.alert("异常:" + ret.error);
                            }
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

    //注销前台
    function setClearPOS() {
        mini.confirm("确定要注销本商户下所有用户的前台登陆信息吗？", "提示",
            function (action) {
                if (action == "ok") {
                    var row = grid.getSelected();
                    if (row) {
                        $.post("../user/setClearPOS", { mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                            }
                            else {
                                mini.alert(ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

</script>